package com.yycx.module.bus.provider.service.impl;

import com.yycx.common.constants.CommonConstants;
import com.yycx.common.mybatis.base.service.impl.BaseServiceImpl;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.mybatis.query.CriteriaSave;
import com.yycx.common.mybatis.query.CriteriaUpdate;
import com.yycx.module.bus.client.entity.BusInvoiceunitBank;
import com.yycx.module.bus.provider.mapper.BusInvoiceunitBankMapper;
import com.yycx.module.bus.provider.service.BusInvoiceunitBankService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 开票单位银行账户接口实现类
 *
 * @author flyme
 * @date 2020-09-10
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BusInvoiceunitBankServiceImpl extends BaseServiceImpl<BusInvoiceunitBankMapper, BusInvoiceunitBank> implements BusInvoiceunitBankService {

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, BusInvoiceunitBank bib, EntityMap extra) {
        bib.setBankState(CommonConstants.ENABLED);
        return ResultBody.ok();
    }


    @Override
    public ResultBody beforeListEntityMap(CriteriaQuery<BusInvoiceunitBank> cq, BusInvoiceunitBank invoiceunitBank, EntityMap requestMap) {
        cq.eq(true, "invoiceUnitId",invoiceunitBank.getInvoiceUnitId());
        cq.eq(true, "bankState", CommonConstants.ENABLED);
        cq.eq(BusInvoiceunitBank.class, "bankType");
        return super.beforeListEntityMap(cq, invoiceunitBank, requestMap);
    }


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<BusInvoiceunitBank> cq, BusInvoiceunitBank bib, EntityMap requestMap) {
        Long invoiceUnitId = bib.getInvoiceUnitId();
        cq.eq(true, "invoiceUnitId", invoiceUnitId);
        cq.orderByDesc("bib.createTime");
        return ResultBody.ok();
    }


}
